package cn.edu.scau.cmi.chenyipeng.Factory;

import java.net.URL;
import java.util.ResourceBundle;

import javafx.collections.FXCollections;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.ChoiceBox;
import javafx.scene.control.Label;

public class FactoryController {

    @FXML
    private ResourceBundle resources;

    @FXML
    private URL location;

    @FXML
    private ChoiceBox<String> chooseMeat;

    @FXML
    private Button makeMeat;

    @FXML
    private Label resultLabel;

    @FXML
    void makeChosenMeat(ActionEvent event) {
    	resultLabel.setWrapText(true);
    	if(chooseMeat.getValue().compareTo("beef") == 0) {
    		Factory f = new BeefFactory();
    		Meat meat = f.makeMeat();
    		resultLabel.setText(resultLabel.getText() + "\n" + meat.getMeat() + meat.toString());
    	}
    	if(chooseMeat.getValue().compareTo("pork") == 0) {
    		Factory f = new PorkFactory();
    		Meat meat = f.makeMeat();
    		resultLabel.setText(resultLabel.getText() + "\n" + meat.getMeat() + meat.toString());
    	}
    	if(chooseMeat.getValue().compareTo("chicken") == 0) {
    		Factory f = new ChickenFactory();
    		Meat meat = f.makeMeat();
    		resultLabel.setText(resultLabel.getText() + "\n" + meat.getMeat() + meat.toString());
    	}
    }

    @FXML
    void initialize() {
        assert chooseMeat != null : "fx:id=\"chooseMeat\" was not injected: check your FXML file 'FactoryUI.fxml'.";
        assert makeMeat != null : "fx:id=\"makeMeat\" was not injected: check your FXML file 'FactoryUI.fxml'.";
        assert resultLabel != null : "fx:id=\"resultLabel\" was not injected: check your FXML file 'FactoryUI.fxml'.";
        chooseMeat.setItems(FXCollections.observableArrayList("beef", "chicken","pork"));
    }
}

